﻿using System.Collections;
using System.Collections.Generic;

namespace IntoLog
{
    public class LogQueue : Queue
    {
        private object locker = new object();

        /// <summary>
        /// 入队
        /// </summary>
        /// <param name="obj"></param>
        public override void Enqueue(object obj)
        {
            lock (locker)
            {
                base.Enqueue(obj);
            }
        }

        /// <summary>
        /// 全部出队
        /// </summary>
        /// <returns></returns>
        public List<object> DequeueAll()
        {
            lock (locker)
            {
                int count = base.Count;
                List<object> list = new List<object>();
                for (int i = 0; i < count; i++)
                {
                    list.Add(base.Dequeue());
                }
                return list;
            }
        }

        /// <summary>
        /// 出队
        /// </summary>
        /// <returns></returns>
        public override object Dequeue()
        {
            lock (locker)
            {
                return base.Dequeue();
            }
        }
    }
}
